package com.rw.daoImpl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.rw.dao.ItemPictureDao;
import com.rw.table.Itempicture;

public class ItemPictureDaoImpl extends HibernateDaoSupport implements ItemPictureDao {

	@Override
	public Itempicture get(Long picId) {

		return this.getHibernateTemplate().get(Itempicture.class, picId);
	}

	@Override
	public boolean delete(Long picId) {

		try {
			this.getHibernateTemplate().delete(this.get(picId));
			return true;
		} catch (Exception e) {

			return false;
		}
		
	}

	@Override
	public boolean modify(Itempicture itempicture) {

		try {
			this.getHibernateTemplate().update(itempicture);
			return true;
		} catch (Exception e) {

			return false;
		}
	}

	@Override
	public boolean addItemPic(Itempicture itempicture) {

		if((Long)this.getHibernateTemplate().save(itempicture) > 0){
			return true;
		}else{
			return false;
		}
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Itempicture> findItemPicByName(String name) {

		return this.getHibernateTemplate().find("select it from Itempicture it where it.itemPicSrc = " + "'" + name + "'");
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Itempicture> findItemPicByItemId(Long itemId) {

		return this.getHibernateTemplate().find("select it from Itempicture it where it.itemPicOwnerId = " + itemId);
	}

	
}
